package com.esri.android.map.popup;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.DataSetObservable;
import android.database.DataSetObserver;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.RectShape;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.core.internal.view.SupportMenu;
import com.esri.android.map.AttachmentManager;
import com.esri.android.map.ags.ArcGISPopupInfo;
import com.esri.core.geodatabase.GeodatabaseFeatureTable;
import com.esri.core.geometry.ShapeModifiers;
import com.esri.core.io.EsriServiceException;
import com.esri.core.map.AttachmentInfo;
import com.esri.core.map.CallbackListener;
import com.esri.core.table.FeatureTable;
import com.tencent.smtt.sdk.TbsListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import okhttp3.internal.ws.RealWebSocket;
import org.codehaus.jackson.util.MinimalPrettyPrinter;
import org.kxml2.wap.Wbxml;

/* loaded from: classes.dex */
public class ArcGISAttachmentsAdapter implements ListAdapter, PopupEditable {
    private static final int h = 1;
    private static final int i = 0;
    Context a;
    Popup b;
    AttachmentManager c;
    String d;
    InternalAttachmentAdapterListener f;
    private int j;
    private long k;
    private int m;
    private final DataSetObservable g = new DataSetObservable();
    protected LinkedHashMap<AttachmentInfo, ATTACHMENT_STATUS> mAttachmentInfos = new LinkedHashMap<>();
    int e = TbsListener.ErrorCode.ERROR_CODE_LOAD_BASE;
    private boolean l = false;
    private Handler n = new Handler(Looper.getMainLooper(), new Handler.Callback() { // from class: com.esri.android.map.popup.ArcGISAttachmentsAdapter.1
        @Override // android.os.Handler.Callback
        public boolean handleMessage(Message message) {
            if (message.what != 0) {
                return false;
            }
            ArcGISAttachmentsAdapter.this.notifyDataSetChanged();
            return false;
        }
    });
    private boolean o = false;

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public enum ATTACHMENT_STATUS {
        CURRENT,
        NEW,
        DELETED
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public interface InternalAttachmentAdapterListener {
        void onAttachmentAdded(AttachmentInfo attachmentInfo);

        void onAttachmentRemoved(AttachmentInfo attachmentInfo);

        void onAttachmentRetrieving();

        void onAttachmentsRetrieved(List<AttachmentInfo> list);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public enum MENU_OPTIONS {
        DOWNLOAD,
        OPEN,
        DELETE
    }

    @Override // android.widget.ListAdapter
    public boolean areAllItemsEnabled() {
        return true;
    }

    @Override // android.widget.Adapter
    public long getItemId(int i2) {
        return i2;
    }

    @Override // android.widget.Adapter
    public int getItemViewType(int i2) {
        return 0;
    }

    @Override // android.widget.Adapter
    public int getViewTypeCount() {
        return 1;
    }

    @Override // android.widget.Adapter
    public boolean hasStableIds() {
        return false;
    }

    @Override // android.widget.Adapter
    public boolean isEmpty() {
        return false;
    }

    @Override // android.widget.ListAdapter
    public boolean isEnabled(int i2) {
        return true;
    }

    @Override // android.widget.Adapter
    public int getCount() {
        LinkedHashMap<AttachmentInfo, ATTACHMENT_STATUS> linkedHashMap = this.mAttachmentInfos;
        int i2 = 0;
        if (linkedHashMap != null && !linkedHashMap.isEmpty()) {
            for (ATTACHMENT_STATUS attachment_status : this.mAttachmentInfos.values()) {
                if (!ATTACHMENT_STATUS.DELETED.equals(attachment_status)) {
                    i2++;
                }
            }
        }
        return i2;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public boolean a() {
        LinkedHashMap<AttachmentInfo, ATTACHMENT_STATUS> linkedHashMap;
        return this.o && (linkedHashMap = this.mAttachmentInfos) != null && linkedHashMap.isEmpty();
    }

    @Override // android.widget.Adapter
    public AttachmentInfo getItem(int i2) {
        ArrayList arrayList = new ArrayList();
        LinkedHashMap<AttachmentInfo, ATTACHMENT_STATUS> linkedHashMap = this.mAttachmentInfos;
        if (linkedHashMap != null && !linkedHashMap.isEmpty()) {
            for (AttachmentInfo attachmentInfo : this.mAttachmentInfos.keySet()) {
                if (!this.mAttachmentInfos.get(attachmentInfo).equals(ATTACHMENT_STATUS.DELETED)) {
                    arrayList.add(attachmentInfo);
                }
            }
            if (arrayList.size() > i2) {
                return (AttachmentInfo) arrayList.get(i2);
            }
        }
        return null;
    }

    public ArcGISAttachmentsAdapter(Context context, Popup popup, File file) {
        ArcGISPopupInfo arcGISPopupInfo;
        String layerUrl;
        this.j = 1;
        this.b = popup;
        this.a = context;
        if (!(popup.a instanceof ArcGISPopupInfo)) {
            arcGISPopupInfo = new ArcGISPopupInfo(this.b.a);
        } else {
            arcGISPopupInfo = (ArcGISPopupInfo) this.b.a;
        }
        if (arcGISPopupInfo != null && ((layerUrl = arcGISPopupInfo.getLayerUrl()) != null || (this.b.a instanceof FeatureTablePopupInfo))) {
            AttachmentManager attachmentManager = new AttachmentManager(context, layerUrl, this.b.c, file);
            this.c = attachmentManager;
            this.d = attachmentManager.getAttachmentDownloadDir().getAbsolutePath();
            this.k = -1L;
            String objectIdField = arcGISPopupInfo.getObjectIdField();
            Object attributeValue = this.b.b.getAttributeValue(objectIdField == null ? "objectid" : objectIdField);
            attributeValue = attributeValue == null ? this.b.b.getAttributeValue("OBJECTID") : attributeValue;
            if (attributeValue != null) {
                if (attributeValue instanceof Integer) {
                    this.k = Integer.parseInt(attributeValue.toString());
                } else if (attributeValue instanceof Long) {
                    this.k = Long.parseLong(attributeValue.toString());
                }
            }
            if (this.k == -1) {
                return;
            }
            if (layerUrl != null && arcGISPopupInfo.isHasAttachments()) {
                this.c.retrieveAttachmentInfos(this.k, new AttachmentManager.AttachmentRetrievalListener() { // from class: com.esri.android.map.popup.ArcGISAttachmentsAdapter.2
                    @Override // com.esri.android.map.AttachmentManager.AttachmentRetrievalListener
                    public void onAttachmentRetrieved(List<AttachmentInfo> list) {
                        for (AttachmentInfo attachmentInfo : list) {
                            ArcGISAttachmentsAdapter.this.mAttachmentInfos.put(attachmentInfo, ATTACHMENT_STATUS.CURRENT);
                        }
                        ArcGISAttachmentsAdapter.this.n.sendEmptyMessage(0);
                        if (ArcGISAttachmentsAdapter.this.f != null) {
                            ArcGISAttachmentsAdapter.this.f.onAttachmentsRetrieved(list);
                        }
                        ArcGISAttachmentsAdapter.this.o = true;
                    }

                    @Override // com.esri.android.map.AttachmentManager.AttachmentRetrievalListener
                    public void onAttachmentRetrieving() {
                        if (ArcGISAttachmentsAdapter.this.f != null) {
                            ArcGISAttachmentsAdapter.this.f.onAttachmentRetrieving();
                        }
                    }
                });
            } else if (arcGISPopupInfo instanceof FeatureTablePopupInfo) {
                FeatureTable table = ((FeatureTablePopupInfo) arcGISPopupInfo).getTable();
                if (table instanceof GeodatabaseFeatureTable) {
                    ((GeodatabaseFeatureTable) table).queryAttachmentInfos(this.k, new CallbackListener<List<AttachmentInfo>>() { // from class: com.esri.android.map.popup.ArcGISAttachmentsAdapter.3
                        @Override // com.esri.core.map.CallbackListener
                        public void onError(Throwable th) {
                            throw new EsriServiceException(th.getMessage());
                        }

                        @Override // com.esri.core.map.CallbackListener
                        /* renamed from: a */
                        public void onCallback(List<AttachmentInfo> list) {
                            if (list != null) {
                                for (AttachmentInfo attachmentInfo : list) {
                                    ArcGISAttachmentsAdapter.this.mAttachmentInfos.put(attachmentInfo, ATTACHMENT_STATUS.CURRENT);
                                }
                            }
                            ArcGISAttachmentsAdapter.this.n.sendEmptyMessage(0);
                            if (ArcGISAttachmentsAdapter.this.f != null) {
                                ArcGISAttachmentsAdapter.this.f.onAttachmentsRetrieved(list);
                            }
                            ArcGISAttachmentsAdapter.this.o = true;
                        }
                    });
                }
            }
        }
        this.j = PopupUtil.convertDpInPixels(context, this.j);
    }

    @Override // android.widget.Adapter
    public View getView(int i2, View view, ViewGroup viewGroup) {
        AttachmentInfo item = getItem(i2);
        if (item != null) {
            AttachmentView attachmentView = new AttachmentView(this.a, item);
            attachmentView.setLayoutParams(new AbsListView.LayoutParams(this.e, PopupUtil.convertDpInPixels(this.a, 133)));
            attachmentView.setEditMode(this.l);
            return attachmentView;
        }
        return null;
    }

    public int getColumnWidth() {
        return this.e;
    }

    public void setColumnWidth(int i2) {
        this.e = i2;
    }

    InternalAttachmentAdapterListener b() {
        return this.f;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void a(InternalAttachmentAdapterListener internalAttachmentAdapterListener) {
        this.f = internalAttachmentAdapterListener;
    }

    @Override // android.widget.Adapter
    public void registerDataSetObserver(DataSetObserver dataSetObserver) {
        this.g.registerObserver(dataSetObserver);
    }

    @Override // android.widget.Adapter
    public void unregisterDataSetObserver(DataSetObserver dataSetObserver) {
        this.g.unregisterObserver(dataSetObserver);
    }

    public void notifyDataSetChanged() {
        this.g.notifyChanged();
    }

    public void notifyDataSetInvalidated() {
        this.g.notifyInvalidated();
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public class AttachmentView extends RelativeLayout implements PopupEditable {
        private static final int j = 0;
        private static final int k = 1;
        private static final int l = 2;
        private static final int t = 1;
        private static final int u = 2;
        ImageView a;
        TextView b;
        AttachmentInfo c;
        boolean d;
        ImageView e;
        a f;
        int g;
        Handler h;
        private final int m;
        private final int n;
        private final int o;
        private final int p;
        private final int q;
        private final int r;
        private final int s;

        public AttachmentView(Context context, AttachmentInfo attachmentInfo) {
            super(context);
            int parseColor = Color.parseColor("#FF0099CC");
            this.m = parseColor;
            int parseColor2 = Color.parseColor("#FF669900");
            this.n = parseColor2;
            int parseColor3 = Color.parseColor("#FFCC0000");
            this.o = parseColor3;
            int parseColor4 = Color.parseColor("#FFA6ACA9");
            this.p = parseColor4;
            int parseColor5 = Color.parseColor("#FF9933CC");
            this.q = parseColor5;
            int parseColor6 = Color.parseColor("#FFAA66CC");
            this.r = parseColor6;
            int parseColor7 = Color.parseColor("#FFA6ACA9");
            this.s = parseColor7;
            this.g = 2;
            this.h = new Handler(new Handler.Callback() { // from class: com.esri.android.map.popup.ArcGISAttachmentsAdapter.AttachmentView.1
                @Override // android.os.Handler.Callback
                public boolean handleMessage(Message message) {
                    int i = message.what;
                    if (i == 0) {
                        AttachmentView.this.f.setEnabled(false);
                        ProgressBar progressBar = new ProgressBar(ArcGISAttachmentsAdapter.this.a);
                        AttachmentView.this.e = new ImageView(ArcGISAttachmentsAdapter.this.a);
                        Drawable indeterminateDrawable = progressBar.getIndeterminateDrawable();
                        if (indeterminateDrawable instanceof Animatable) {
                            ((Animatable) indeterminateDrawable).start();
                            indeterminateDrawable.setCallback(AttachmentView.this.a);
                        }
                        AttachmentView.this.e.setBackgroundDrawable(indeterminateDrawable);
                        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(-2, -2);
                        layoutParams.addRule(13, -1);
                        AttachmentView attachmentView = AttachmentView.this;
                        attachmentView.addView(attachmentView.e, layoutParams);
                    } else if (i == 1) {
                        AttachmentView.this.f.setEnabled(true);
                        if (AttachmentView.this.e != null) {
                            AttachmentView attachmentView2 = AttachmentView.this;
                            attachmentView2.removeView(attachmentView2.e);
                            AttachmentView.this.e = null;
                        }
                        if (1 == AttachmentView.this.g) {
                            AttachmentView.this.a.setImageBitmap(AttachmentView.this.a((File) message.obj));
                            AttachmentView.this.a.setScaleType(ImageView.ScaleType.CENTER_CROP);
                            AttachmentView.this.a.postInvalidate();
                            AttachmentView.this.b.setVisibility(8);
                        }
                        AttachmentView.this.f.a();
                        AttachmentView.this.d = true;
                    } else if (i == 2) {
                        AttachmentView.this.f.setEnabled(true);
                        if (AttachmentView.this.e != null) {
                            AttachmentView attachmentView3 = AttachmentView.this;
                            attachmentView3.removeView(attachmentView3.e);
                            AttachmentView.this.e = null;
                        }
                        AttachmentView.this.a(((Exception) message.obj).getMessage());
                    }
                    return false;
                }
            });
            this.c = attachmentInfo;
            String[] split = attachmentInfo.getContentType().split("/");
            String str = split[0];
            String str2 = split[1];
            this.b = new TextView(context);
            ImageView imageView = new ImageView(context);
            this.a = imageView;
            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
            File file = new File(ArcGISAttachmentsAdapter.this.d, ArcGISAttachmentsAdapter.this.a(this.c));
            if (file.exists()) {
                this.d = true;
            }
            if ("video".equalsIgnoreCase(str)) {
                this.a.setBackgroundColor(parseColor5);
            } else if ("image".equalsIgnoreCase(str)) {
                this.g = 1;
                if (file.exists()) {
                    this.a.setImageBitmap(a(file));
                    this.a.setScaleType(ImageView.ScaleType.CENTER_CROP);
                    this.b.setVisibility(8);
                } else {
                    this.a.setBackgroundColor(parseColor4);
                }
            } else if ("audio".equalsIgnoreCase(str)) {
                this.a.setBackgroundColor(parseColor6);
            } else if ("application".equalsIgnoreCase(str)) {
                if ("msword".equals(str2) || "vnd.openxmlformats-officedocument.wordprocessingml.document".equals(str2)) {
                    this.a.setBackgroundColor(parseColor);
                } else if ("excel".equals(str2) || "vnd.openxmlformats-officedocument.spreadsheetml.sheet".equals(str2)) {
                    this.a.setBackgroundColor(parseColor2);
                } else if ("pdf".equals(str2)) {
                    this.a.setBackgroundColor(parseColor3);
                } else {
                    this.a.setBackgroundColor(parseColor7);
                }
            } else {
                this.a.setBackgroundColor(parseColor7);
            }
            this.a.setOnClickListener(new View.OnClickListener() { // from class: com.esri.android.map.popup.ArcGISAttachmentsAdapter.AttachmentView.2
                @Override // android.view.View.OnClickListener
                public void onClick(View view) {
                    if (!AttachmentView.this.d) {
                        if (!(ArcGISAttachmentsAdapter.this.b.a instanceof FeatureTablePopupInfo)) {
                            ArcGISAttachmentsAdapter.this.c.downloadAttachment(ArcGISAttachmentsAdapter.this.k, (int) AttachmentView.this.c.getId(), ArcGISAttachmentsAdapter.this.a(AttachmentView.this.c), new AttachmentManager.AttachmentDownloadListener() { // from class: com.esri.android.map.popup.ArcGISAttachmentsAdapter.AttachmentView.2.1
                                @Override // com.esri.android.map.AttachmentManager.AttachmentDownloadListener
                                public void onAttachmentDownloading() {
                                    AttachmentView.this.h.sendEmptyMessage(0);
                                }

                                @Override // com.esri.android.map.AttachmentManager.AttachmentDownloadListener
                                public void onAttachmentDownloaded(File file2) {
                                    Message obtainMessage = AttachmentView.this.h.obtainMessage(1);
                                    obtainMessage.obj = file2;
                                    obtainMessage.sendToTarget();
                                }

                                @Override // com.esri.android.map.AttachmentManager.AttachmentDownloadListener
                                public void onAttachmentDownloadFailed(Exception exc) {
                                    Message obtainMessage = AttachmentView.this.h.obtainMessage(2);
                                    obtainMessage.obj = exc;
                                    obtainMessage.sendToTarget();
                                }
                            });
                            return;
                        } else {
                            AttachmentView.this.a();
                            return;
                        }
                    }
                    File file2 = new File(ArcGISAttachmentsAdapter.this.d, ArcGISAttachmentsAdapter.this.a(AttachmentView.this.c));
                    if (file2.exists()) {
                        Intent intent = new Intent();
                        intent.setAction("android.intent.action.VIEW");
                        intent.setDataAndType(Uri.fromFile(file2), AttachmentView.this.c.getContentType());
                        intent.setFlags(ShapeModifiers.ShapeHasTextures);
                        try {
                            ((Activity) AttachmentView.this.getContext()).startActivity(intent);
                        } catch (ActivityNotFoundException unused) {
                            Toast.makeText(AttachmentView.this.getContext(), Popup.getPopupString("ags_no_application_available_to_view_this_file_type", "No application available to view this file type", AttachmentView.this.getContext()), 0).show();
                        }
                    }
                }
            });
            addView(this.a, -1, -1);
            this.b.setId(1);
            String[] split2 = this.c.getName().split("[.]");
            this.b.setText((split2.length >= 2 ? split2[split2.length - 1] : str).toUpperCase(Locale.getDefault()));
            this.b.setTextSize(1, 30.0f);
            this.b.setTypeface(Typeface.DEFAULT_BOLD);
            this.b.setTextColor(-1);
            RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(-2, -2);
            layoutParams.addRule(13, -1);
            addView(this.b, layoutParams);
            a aVar = new a(ArcGISAttachmentsAdapter.this.a);
            this.f = aVar;
            if (this.d) {
                aVar.a();
            }
            RelativeLayout.LayoutParams layoutParams2 = new RelativeLayout.LayoutParams(-1, -2);
            layoutParams2.addRule(12, -1);
            addView(this.f, layoutParams2);
        }

        /* JADX INFO: Access modifiers changed from: private */
        public void a(String str) {
            TextView textView = new TextView(getContext());
            textView.setTextColor(SupportMenu.CATEGORY_MASK);
            textView.setTypeface(Typeface.DEFAULT_BOLD, 1);
            textView.setPadding(5, 3, 5, 3);
            textView.setTextSize(1, 10.0f);
            String popupString = Popup.getPopupString("ags_error", "Error: ", ArcGISAttachmentsAdapter.this.a);
            textView.setText(popupString + ":\n" + str);
            textView.setGravity(1);
            RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(-1, -2);
            layoutParams.addRule(3, this.b.getId());
            addView(textView, layoutParams);
        }

        /* JADX WARN: Code restructure failed: missing block: B:22:0x0048, code lost:
            if (r3 == null) goto L8;
         */
        /* JADX WARN: Removed duplicated region for block: B:51:0x008b A[EXC_TOP_SPLITTER, SYNTHETIC] */
        /*
            Code decompiled incorrectly, please refer to instructions dump.
            To view partially-correct code enable 'Show inconsistent code' option in preferences
        */
        android.graphics.Bitmap a(java.io.File r8) {
            /*
                r7 = this;
                long r0 = r8.length()
                int r1 = (int) r0
                byte[] r0 = new byte[r1]
                r2 = 0
                java.io.FileInputStream r3 = new java.io.FileInputStream     // Catch: java.lang.Throwable -> L1a java.io.IOException -> L1d java.io.FileNotFoundException -> L34
                r3.<init>(r8)     // Catch: java.lang.Throwable -> L1a java.io.IOException -> L1d java.io.FileNotFoundException -> L34
                r3.read(r0)     // Catch: java.io.IOException -> L16 java.io.FileNotFoundException -> L18 java.lang.Throwable -> L87
            L10:
                r3.close()     // Catch: java.io.IOException -> L14
                goto L4b
            L14:
                goto L4b
            L16:
                r8 = move-exception
                goto L1f
            L18:
                r8 = move-exception
                goto L36
            L1a:
                r8 = move-exception
                goto L89
            L1d:
                r8 = move-exception
                r3 = r2
            L1f:
                java.lang.String r4 = "ags_attachment_could_not_be_read_from_disk"
                java.lang.String r5 = "The Attachment could not be read from disk"
                com.esri.android.map.popup.ArcGISAttachmentsAdapter r6 = com.esri.android.map.popup.ArcGISAttachmentsAdapter.this     // Catch: java.lang.Throwable -> L87
                android.content.Context r6 = r6.a     // Catch: java.lang.Throwable -> L87
                java.lang.String r4 = com.esri.android.map.popup.Popup.getPopupString(r4, r5, r6)     // Catch: java.lang.Throwable -> L87
                r7.a(r4)     // Catch: java.lang.Throwable -> L87
                r8.printStackTrace()     // Catch: java.lang.Throwable -> L87
                if (r3 == 0) goto L4b
                goto L10
            L34:
                r8 = move-exception
                r3 = r2
            L36:
                java.lang.String r4 = "ags_attachment_does_not_exist_on_disk"
                java.lang.String r5 = "The Attachment does not exist on disk"
                com.esri.android.map.popup.ArcGISAttachmentsAdapter r6 = com.esri.android.map.popup.ArcGISAttachmentsAdapter.this     // Catch: java.lang.Throwable -> L87
                android.content.Context r6 = r6.a     // Catch: java.lang.Throwable -> L87
                java.lang.String r4 = com.esri.android.map.popup.Popup.getPopupString(r4, r5, r6)     // Catch: java.lang.Throwable -> L87
                r7.a(r4)     // Catch: java.lang.Throwable -> L87
                r8.printStackTrace()     // Catch: java.lang.Throwable -> L87
                if (r3 == 0) goto L4b
                goto L10
            L4b:
                android.graphics.BitmapFactory$Options r8 = new android.graphics.BitmapFactory$Options
                r8.<init>()
                r3 = 1
                r8.inJustDecodeBounds = r3
                r4 = 0
                android.graphics.BitmapFactory.decodeByteArray(r0, r4, r1, r8)
                int r5 = r8.outWidth
                r6 = -1
                if (r5 == r6) goto L86
                int r5 = r8.outHeight
                if (r5 != r6) goto L61
                goto L86
            L61:
                int r2 = r8.outHeight
                int r5 = r8.outWidth
                if (r2 <= r5) goto L6a
                int r8 = r8.outHeight
                goto L6c
            L6a:
                int r8 = r8.outWidth
            L6c:
                r2 = 1
            L6d:
                int r5 = r8 / r2
                com.esri.android.map.popup.ArcGISAttachmentsAdapter r6 = com.esri.android.map.popup.ArcGISAttachmentsAdapter.this
                int r6 = r6.e
                if (r5 <= r6) goto L78
                int r2 = r2 + 1
                goto L6d
            L78:
                android.graphics.BitmapFactory$Options r8 = new android.graphics.BitmapFactory$Options
                r8.<init>()
                r8.inSampleSize = r2
                r8.inPurgeable = r3
                android.graphics.Bitmap r8 = android.graphics.BitmapFactory.decodeByteArray(r0, r4, r1, r8)
                return r8
            L86:
                return r2
            L87:
                r8 = move-exception
                r2 = r3
            L89:
                if (r2 == 0) goto L8e
                r2.close()     // Catch: java.io.IOException -> L8e
            L8e:
                goto L90
            L8f:
                throw r8
            L90:
                goto L8f
            */
            throw new UnsupportedOperationException("Method not decompiled: com.esri.android.map.popup.ArcGISAttachmentsAdapter.AttachmentView.a(java.io.File):android.graphics.Bitmap");
        }

        /* JADX INFO: Access modifiers changed from: private */
        /* loaded from: classes.dex */
        public class a extends LinearLayout implements PopupEditable {
            AttachmentMenuBackgroundDrawable a;
            private TextView c;
            private View.OnClickListener d;
            private boolean e;

            public a(Context context) {
                super(context);
                String str;
                this.e = false;
                setOrientation(1);
                setPadding(0, 0, 0, 0);
                AttachmentMenuBackgroundDrawable attachmentMenuBackgroundDrawable = new AttachmentMenuBackgroundDrawable();
                this.a = attachmentMenuBackgroundDrawable;
                setBackgroundDrawable(attachmentMenuBackgroundDrawable);
                this.d = new AnonymousClass1(AttachmentView.this);
                TextView textView = new TextView(ArcGISAttachmentsAdapter.this.a);
                textView.setTextColor(-1);
                textView.setSingleLine();
                textView.setMovementMethod(new ScrollingMovementMethod());
                textView.setSelected(true);
                textView.setPadding(5, 0, 5, 0);
                textView.setGravity(3);
                textView.setText(AttachmentView.this.c.getName());
                addView(textView);
                TextView textView2 = new TextView(ArcGISAttachmentsAdapter.this.a);
                this.c = textView2;
                textView2.setTextColor(-1);
                this.c.setSingleLine();
                this.c.setPadding(5, 0, 5, 0);
                this.c.setGravity(3);
                if (AttachmentView.this.c.getSize() / RealWebSocket.DEFAULT_MINIMUM_DEFLATE_SIZE < 1000) {
                    String popupString = Popup.getPopupString("ags_kilobyte_abbreviation", ArcGISAttachmentsAdapter.this.a);
                    str = (AttachmentView.this.c.getSize() / RealWebSocket.DEFAULT_MINIMUM_DEFLATE_SIZE) + MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR + (popupString == null ? "KB" : popupString);
                } else {
                    String popupString2 = Popup.getPopupString("ags_megabyte_abbreviation", ArcGISAttachmentsAdapter.this.a);
                    str = ((AttachmentView.this.c.getSize() / RealWebSocket.DEFAULT_MINIMUM_DEFLATE_SIZE) / RealWebSocket.DEFAULT_MINIMUM_DEFLATE_SIZE) + MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR + (popupString2 == null ? "MB" : popupString2);
                }
                this.c.setText(str);
                addView(this.c);
            }

            /* renamed from: com.esri.android.map.popup.ArcGISAttachmentsAdapter$AttachmentView$a$1  reason: invalid class name */
            /* loaded from: classes.dex */
            class AnonymousClass1 implements View.OnClickListener {
                b a;
                final /* synthetic */ AttachmentView b;

                AnonymousClass1(AttachmentView attachmentView) {
                    this.b = attachmentView;
                }

                @Override // android.view.View.OnClickListener
                public void onClick(View view) {
                    if (this.a == null) {
                        this.a = new b(AttachmentView.this.f);
                    }
                    this.a.a(new c());
                    this.a.a(new AdapterView.OnItemSelectedListener() { // from class: com.esri.android.map.popup.ArcGISAttachmentsAdapter.AttachmentView.a.1.1
                        @Override // android.widget.AdapterView.OnItemSelectedListener
                        public void onNothingSelected(AdapterView<?> adapterView) {
                        }

                        @Override // android.widget.AdapterView.OnItemSelectedListener
                        public void onItemSelected(AdapterView<?> adapterView, View view2, int i, long j) {
                            int i2 = AnonymousClass4.a[((c) AnonymousClass1.this.a.b()).getItem(i).ordinal()];
                            if (i2 == 1) {
                                String a = ArcGISAttachmentsAdapter.this.a(AttachmentView.this.c);
                                if (a != null) {
                                    ArcGISAttachmentsAdapter.this.c.deleteAttachment(a);
                                }
                                if (ATTACHMENT_STATUS.NEW.equals(ArcGISAttachmentsAdapter.this.mAttachmentInfos.get(AttachmentView.this.c))) {
                                    ArcGISAttachmentsAdapter.this.mAttachmentInfos.remove(AttachmentView.this.c);
                                } else {
                                    ArcGISAttachmentsAdapter.this.mAttachmentInfos.put(AttachmentView.this.c, ATTACHMENT_STATUS.DELETED);
                                    if (ArcGISAttachmentsAdapter.this.f != null) {
                                        ArcGISAttachmentsAdapter.this.f.onAttachmentRemoved(AttachmentView.this.c);
                                    }
                                    if (ArcGISAttachmentsAdapter.this.b.getPopupListener() != null) {
                                        ArcGISAttachmentsAdapter.this.b.getPopupListener().onPopupModified();
                                    }
                                }
                                ArcGISAttachmentsAdapter.this.notifyDataSetChanged();
                                AttachmentView.this.postInvalidate();
                            } else if (i2 == 2) {
                                if (!(ArcGISAttachmentsAdapter.this.b.a instanceof FeatureTablePopupInfo)) {
                                    ArcGISAttachmentsAdapter.this.c.downloadAttachment(ArcGISAttachmentsAdapter.this.k, (int) AttachmentView.this.c.getId(), ArcGISAttachmentsAdapter.this.a(AttachmentView.this.c), new AttachmentManager.AttachmentDownloadListener() { // from class: com.esri.android.map.popup.ArcGISAttachmentsAdapter.AttachmentView.a.1.1.1
                                        @Override // com.esri.android.map.AttachmentManager.AttachmentDownloadListener
                                        public void onAttachmentDownloading() {
                                            AttachmentView.this.h.sendEmptyMessage(0);
                                        }

                                        @Override // com.esri.android.map.AttachmentManager.AttachmentDownloadListener
                                        public void onAttachmentDownloaded(File file) {
                                            Message obtainMessage = AttachmentView.this.h.obtainMessage(1);
                                            obtainMessage.obj = file;
                                            obtainMessage.sendToTarget();
                                        }

                                        @Override // com.esri.android.map.AttachmentManager.AttachmentDownloadListener
                                        public void onAttachmentDownloadFailed(Exception exc) {
                                            Message obtainMessage = AttachmentView.this.h.obtainMessage(2);
                                            obtainMessage.obj = exc;
                                            obtainMessage.sendToTarget();
                                        }
                                    });
                                } else {
                                    AttachmentView.this.a();
                                }
                            } else if (i2 != 3) {
                            } else {
                                File file = new File(ArcGISAttachmentsAdapter.this.d, ArcGISAttachmentsAdapter.this.a(AttachmentView.this.c));
                                if (file.exists()) {
                                    Intent intent = new Intent();
                                    intent.setAction("android.intent.action.VIEW");
                                    intent.setDataAndType(Uri.fromFile(file), AttachmentView.this.c.getContentType());
                                    intent.setFlags(ShapeModifiers.ShapeHasTextures);
                                    try {
                                        ((Activity) a.this.getContext()).startActivity(intent);
                                    } catch (ActivityNotFoundException unused) {
                                        Toast.makeText(a.this.getContext(), Popup.getPopupString("ags_no_application_available_to_view_this_file_type", "No application available to view this file type", a.this.getContext()), 0).show();
                                    }
                                }
                            }
                        }
                    });
                    this.a.a();
                }
            }

            public void a() {
                this.c.setText(Popup.getPopupString("ags_attachment_downloaded", "Downloaded", getContext()));
            }

            @Override // com.esri.android.map.popup.PopupEditable
            public void setEditMode(boolean z) {
                if (z != this.e) {
                    this.a.setEditMode(z);
                    setOnClickListener(z ? this.d : null);
                    this.e = z;
                }
            }
        }

        /* JADX INFO: Access modifiers changed from: protected */
        /* loaded from: classes.dex */
        public class AttachmentMenuBackgroundDrawable extends ShapeDrawable implements PopupEditable {
            boolean a;

            public AttachmentMenuBackgroundDrawable() {
                super(new RectShape());
                this.a = false;
            }

            @Override // android.graphics.drawable.ShapeDrawable, android.graphics.drawable.Drawable
            public void draw(Canvas canvas) {
                Paint paint = new Paint();
                Rect bounds = getBounds();
                RectF rectF = new RectF(bounds.left, bounds.top, bounds.right, bounds.bottom);
                paint.setAntiAlias(true);
                paint.setColor(Color.argb(180, 100, 100, 100));
                paint.setStyle(Paint.Style.FILL);
                canvas.drawRect(rectF, paint);
                paint.setStrokeWidth(2.0f);
                paint.setAntiAlias(true);
                paint.setStyle(Paint.Style.FILL);
                paint.setColor(org.achartengine.internal.renderer.a.c);
                if (this.a) {
                    Path path = new Path();
                    int i = ((bounds.bottom - bounds.top) / 3) - 2;
                    path.moveTo(bounds.right - 2, bounds.bottom - 2);
                    path.lineTo(bounds.right - 2, bounds.bottom - i);
                    path.lineTo(bounds.right - i, bounds.bottom - 2);
                    path.close();
                    canvas.drawPath(path, paint);
                }
            }

            @Override // com.esri.android.map.popup.PopupEditable
            public void setEditMode(boolean z) {
                this.a = z;
            }
        }

        /* loaded from: classes.dex */
        private class c implements ListAdapter {
            private MENU_OPTIONS[] b = {MENU_OPTIONS.DOWNLOAD, MENU_OPTIONS.DELETE};
            private MENU_OPTIONS[] c = {MENU_OPTIONS.OPEN, MENU_OPTIONS.DELETE};

            @Override // android.widget.ListAdapter
            public boolean areAllItemsEnabled() {
                return true;
            }

            @Override // android.widget.Adapter
            public long getItemId(int i) {
                return i;
            }

            @Override // android.widget.Adapter
            public int getItemViewType(int i) {
                return 1;
            }

            @Override // android.widget.Adapter
            public int getViewTypeCount() {
                return 1;
            }

            @Override // android.widget.Adapter
            public boolean hasStableIds() {
                return false;
            }

            @Override // android.widget.Adapter
            public boolean isEmpty() {
                return false;
            }

            @Override // android.widget.ListAdapter
            public boolean isEnabled(int i) {
                return true;
            }

            @Override // android.widget.Adapter
            public void registerDataSetObserver(DataSetObserver dataSetObserver) {
            }

            @Override // android.widget.Adapter
            public void unregisterDataSetObserver(DataSetObserver dataSetObserver) {
            }

            public c() {
            }

            @Override // android.widget.Adapter
            public int getCount() {
                return AttachmentView.this.d ? this.c.length : this.b.length;
            }

            @Override // android.widget.Adapter
            /* renamed from: a */
            public MENU_OPTIONS getItem(int i) {
                if (AttachmentView.this.d) {
                    MENU_OPTIONS[] menu_optionsArr = this.c;
                    if (i < menu_optionsArr.length) {
                        return menu_optionsArr[i];
                    }
                }
                MENU_OPTIONS[] menu_optionsArr2 = this.b;
                if (i < menu_optionsArr2.length) {
                    return menu_optionsArr2[i];
                }
                return null;
            }

            @Override // android.widget.Adapter
            public View getView(int i, View view, ViewGroup viewGroup) {
                TextView textView;
                String popupString;
                if (view != null) {
                    textView = (TextView) view;
                } else {
                    textView = new TextView(ArcGISAttachmentsAdapter.this.a);
                    textView.setMinHeight(PopupUtil.convertDpInPixels(ArcGISAttachmentsAdapter.this.a, 48));
                    textView.setMinWidth(PopupUtil.convertDpInPixels(ArcGISAttachmentsAdapter.this.a, Wbxml.LITERAL_AC));
                    textView.setGravity(19);
                    textView.setPadding(PopupUtil.convertDpInPixels(ArcGISAttachmentsAdapter.this.a, 16), 0, PopupUtil.convertDpInPixels(ArcGISAttachmentsAdapter.this.a, 16), 0);
                    textView.setTextSize(2, 18.0f);
                    textView.setBackgroundColor(-1);
                    textView.setLayoutParams(new AbsListView.LayoutParams(-1, -2));
                }
                String str = null;
                int i2 = AnonymousClass4.a[getItem(i).ordinal()];
                if (i2 == 1) {
                    popupString = Popup.getPopupString("ags_delete", ArcGISAttachmentsAdapter.this.a);
                    if (popupString == null) {
                        popupString = "Delete";
                    }
                } else if (i2 == 2) {
                    popupString = Popup.getPopupString("ags_download", ArcGISAttachmentsAdapter.this.a);
                    if (popupString == null) {
                        popupString = "Download";
                    }
                } else {
                    if (i2 == 3) {
                        popupString = Popup.getPopupString("ags_open", ArcGISAttachmentsAdapter.this.a);
                        if (popupString == null) {
                            popupString = "Open";
                        }
                    }
                    textView.setText(str);
                    return textView;
                }
                str = popupString;
                textView.setText(str);
                return textView;
            }
        }

        /* loaded from: classes.dex */
        private class b {
            PopupWindow a;
            ListView b;
            private View d;

            public b(View view) {
                ListView listView = new ListView(view.getContext());
                this.b = listView;
                listView.setBackgroundColor(-12303292);
                this.b.setPadding(2, 2, 2, 2);
                this.b.setLayoutParams(new RelativeLayout.LayoutParams(-1, -2));
                this.b.setOnItemClickListener(new AdapterView.OnItemClickListener() { // from class: com.esri.android.map.popup.ArcGISAttachmentsAdapter.AttachmentView.b.1
                    @Override // android.widget.AdapterView.OnItemClickListener
                    public void onItemClick(AdapterView<?> adapterView, View view2, int i, long j) {
                        if (b.this.b.getOnItemSelectedListener() != null) {
                            b.this.b.getOnItemSelectedListener().onItemSelected(adapterView, view2, i, j);
                        }
                        b.this.a.dismiss();
                    }
                });
                this.d = view;
                this.a = new PopupWindow(this.b);
            }

            public void a() {
                this.a.setWidth(this.d.getWidth());
                this.a.setHeight(-2);
                this.a.setBackgroundDrawable(new BitmapDrawable());
                this.a.setTouchable(true);
                this.a.setFocusable(true);
                this.a.setOutsideTouchable(true);
                this.a.setClippingEnabled(false);
                this.a.showAsDropDown(this.d);
                this.b.measure(this.d.getWidth(), 0);
                this.a.update(this.d, 0, 0, this.b.getMeasuredWidth(), Math.round(this.b.getMeasuredHeight() * b().getCount()));
            }

            public void a(AdapterView.OnItemSelectedListener onItemSelectedListener) {
                this.b.setOnItemSelectedListener(onItemSelectedListener);
            }

            public ListAdapter b() {
                return this.b.getAdapter();
            }

            public void a(ListAdapter listAdapter) {
                this.b.setAdapter(listAdapter);
            }
        }

        @Override // com.esri.android.map.popup.PopupEditable
        public void setEditMode(boolean z) {
            this.f.setEditMode(z);
        }

        /* JADX INFO: Access modifiers changed from: private */
        public void a() {
            FeatureTable table = ((FeatureTablePopupInfo) ArcGISAttachmentsAdapter.this.b.a).getTable();
            if (table instanceof GeodatabaseFeatureTable) {
                this.h.sendEmptyMessage(0);
                ((GeodatabaseFeatureTable) table).retrieveAttachment(ArcGISAttachmentsAdapter.this.k, this.c.getId(), new CallbackListener<InputStream>() { // from class: com.esri.android.map.popup.ArcGISAttachmentsAdapter.AttachmentView.3
                    @Override // com.esri.core.map.CallbackListener
                    public void onError(Throwable th) {
                        Message obtainMessage = AttachmentView.this.h.obtainMessage(2);
                        obtainMessage.obj = th;
                        obtainMessage.sendToTarget();
                    }

                    @Override // com.esri.core.map.CallbackListener
                    /* renamed from: a */
                    public void onCallback(InputStream inputStream) {
                        Message obtainMessage = AttachmentView.this.h.obtainMessage(1);
                        File attachmentFile = ArcGISAttachmentsAdapter.this.c.getAttachmentFile(ArcGISAttachmentsAdapter.this.a(AttachmentView.this.c));
                        byte[] bArr = new byte[1024];
                        FileOutputStream fileOutputStream = null;
                        try {
                            try {
                                try {
                                    FileOutputStream fileOutputStream2 = new FileOutputStream(attachmentFile);
                                    while (inputStream.read(bArr) != -1) {
                                        try {
                                            fileOutputStream2.write(bArr);
                                        } catch (IOException e) {
                                            e = e;
                                            fileOutputStream = fileOutputStream2;
                                            e.printStackTrace();
                                            if (inputStream != null) {
                                                inputStream.close();
                                            }
                                            if (fileOutputStream != null) {
                                                fileOutputStream.close();
                                            }
                                            obtainMessage.sendToTarget();
                                        } catch (Throwable th) {
                                            th = th;
                                            fileOutputStream = fileOutputStream2;
                                            if (inputStream != null) {
                                                try {
                                                    inputStream.close();
                                                } catch (Exception unused) {
                                                    throw th;
                                                }
                                            }
                                            if (fileOutputStream != null) {
                                                fileOutputStream.close();
                                            }
                                            throw th;
                                        }
                                    }
                                    obtainMessage.obj = attachmentFile;
                                    if (inputStream != null) {
                                        inputStream.close();
                                    }
                                    fileOutputStream2.close();
                                } catch (Throwable th2) {
                                    th = th2;
                                }
                            } catch (IOException e2) {
                                e = e2;
                            }
                        } catch (Exception unused2) {
                        }
                        obtainMessage.sendToTarget();
                    }
                });
            }
        }
    }

    /* renamed from: com.esri.android.map.popup.ArcGISAttachmentsAdapter$4  reason: invalid class name */
    /* loaded from: classes.dex */
    static /* synthetic */ class AnonymousClass4 {
        static final /* synthetic */ int[] a;

        static {
            int[] iArr = new int[MENU_OPTIONS.values().length];
            a = iArr;
            try {
                iArr[MENU_OPTIONS.DELETE.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                a[MENU_OPTIONS.DOWNLOAD.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                a[MENU_OPTIONS.OPEN.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
        }
    }

    @Override // com.esri.android.map.popup.PopupEditable
    public void setEditMode(boolean z) {
        if (z != this.l) {
            this.l = z;
            this.n.sendEmptyMessage(0);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public List<File> c() {
        ArrayList arrayList = new ArrayList();
        for (AttachmentInfo attachmentInfo : this.mAttachmentInfos.keySet()) {
            if (ATTACHMENT_STATUS.NEW.equals(this.mAttachmentInfos.get(attachmentInfo))) {
                arrayList.add(this.c.getAttachmentFile(a(attachmentInfo)));
            }
        }
        return arrayList;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public List<Integer> d() {
        ArrayList arrayList = new ArrayList();
        for (AttachmentInfo attachmentInfo : this.mAttachmentInfos.keySet()) {
            if (ATTACHMENT_STATUS.DELETED.equals(this.mAttachmentInfos.get(attachmentInfo))) {
                arrayList.add(Integer.valueOf((int) attachmentInfo.getId()));
            }
        }
        return arrayList;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void a(Uri uri) {
        AttachmentInfo a;
        File file = null;
        if ("content".equals(uri.getScheme())) {
            Cursor query = this.a.getContentResolver().query(uri, new String[]{"_data"}, null, null, null);
            int columnIndexOrThrow = query.getColumnIndexOrThrow("_data");
            query.moveToFirst();
            String string = query.getString(columnIndexOrThrow);
            if (string != null) {
                String substring = string.substring(string.lastIndexOf("."));
                file = new File(string.replace(substring, substring.toLowerCase()));
            }
        } else if ("file".equals(uri.getScheme())) {
            try {
                file = new File(new URI(uri.toString()));
            } catch (URISyntaxException unused) {
            }
        }
        if (file == null || (a = a(file)) == null) {
            return;
        }
        this.mAttachmentInfos.put(a, ATTACHMENT_STATUS.NEW);
        InternalAttachmentAdapterListener internalAttachmentAdapterListener = this.f;
        if (internalAttachmentAdapterListener != null) {
            internalAttachmentAdapterListener.onAttachmentAdded(a);
        }
        this.n.sendEmptyMessage(0);
        if (this.b.getPopupListener() != null) {
            this.b.getPopupListener().onPopupModified();
        }
    }

    String a(AttachmentInfo attachmentInfo) {
        if (this.b.getPopupInfo() instanceof ArcGISPopupInfo) {
            ArcGISPopupInfo arcGISPopupInfo = (ArcGISPopupInfo) this.b.getPopupInfo();
            if (arcGISPopupInfo.getLayerName() == null) {
                return null;
            }
            return arcGISPopupInfo.getLayerName() + "_" + this.k + "_" + attachmentInfo.getId() + "_" + attachmentInfo.getName();
        }
        return null;
    }

    /* JADX WARN: Removed duplicated region for block: B:33:0x0099  */
    /* JADX WARN: Removed duplicated region for block: B:35:0x009c A[Catch: Exception -> 0x0097, TRY_LEAVE, TryCatch #2 {Exception -> 0x0097, blocks: (B:31:0x008d, B:35:0x009c), top: B:41:0x008d }] */
    /* JADX WARN: Removed duplicated region for block: B:37:0x00a5  */
    /* JADX WARN: Removed duplicated region for block: B:41:0x008d A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    com.esri.core.map.AttachmentInfo a(java.io.File r9) {
        /*
            r8 = this;
            java.lang.String r0 = "."
            r1 = 0
            if (r9 == 0) goto Lb4
            boolean r2 = r9.exists()
            if (r2 != 0) goto Ld
            goto Lb4
        Ld:
            org.codehaus.jackson.JsonFactory r2 = new org.codehaus.jackson.JsonFactory     // Catch: java.io.IOException -> L7f org.codehaus.jackson.JsonGenerationException -> L85
            r2.<init>()     // Catch: java.io.IOException -> L7f org.codehaus.jackson.JsonGenerationException -> L85
            java.io.StringWriter r3 = new java.io.StringWriter     // Catch: java.io.IOException -> L7f org.codehaus.jackson.JsonGenerationException -> L85
            r3.<init>()     // Catch: java.io.IOException -> L7f org.codehaus.jackson.JsonGenerationException -> L85
            org.codehaus.jackson.JsonGenerator r2 = r2.createJsonGenerator(r3)     // Catch: java.io.IOException -> L7f org.codehaus.jackson.JsonGenerationException -> L85
            r2.writeStartObject()     // Catch: java.io.IOException -> L7f org.codehaus.jackson.JsonGenerationException -> L85
            java.lang.String r4 = "id"
            int r5 = r8.m     // Catch: java.io.IOException -> L7f org.codehaus.jackson.JsonGenerationException -> L85
            r2.writeNumberField(r4, r5)     // Catch: java.io.IOException -> L7f org.codehaus.jackson.JsonGenerationException -> L85
            java.lang.String r4 = "size"
            long r5 = r9.length()     // Catch: java.io.IOException -> L7f org.codehaus.jackson.JsonGenerationException -> L85
            r2.writeNumberField(r4, r5)     // Catch: java.io.IOException -> L7f org.codehaus.jackson.JsonGenerationException -> L85
            java.lang.String r4 = "name"
            java.lang.String r5 = r9.getName()     // Catch: java.io.IOException -> L7f org.codehaus.jackson.JsonGenerationException -> L85
            r2.writeStringField(r4, r5)     // Catch: java.io.IOException -> L7f org.codehaus.jackson.JsonGenerationException -> L85
            java.lang.String r4 = "application/octet-stream"
            java.lang.String r5 = r9.getAbsolutePath()     // Catch: java.io.IOException -> L7f org.codehaus.jackson.JsonGenerationException -> L85
            boolean r6 = r5.contains(r0)     // Catch: java.io.IOException -> L7f org.codehaus.jackson.JsonGenerationException -> L85
            if (r6 == 0) goto L62
            int r0 = r5.lastIndexOf(r0)     // Catch: java.io.IOException -> L7f org.codehaus.jackson.JsonGenerationException -> L85
            int r0 = r0 + 1
            java.lang.String r0 = r5.substring(r0)     // Catch: java.io.IOException -> L7f org.codehaus.jackson.JsonGenerationException -> L85
            if (r0 == 0) goto L62
            java.lang.String r5 = ""
            boolean r5 = r5.equals(r0)     // Catch: java.io.IOException -> L7f org.codehaus.jackson.JsonGenerationException -> L85
            if (r5 != 0) goto L62
            android.webkit.MimeTypeMap r5 = android.webkit.MimeTypeMap.getSingleton()     // Catch: java.io.IOException -> L7f org.codehaus.jackson.JsonGenerationException -> L85
            java.lang.String r0 = r5.getMimeTypeFromExtension(r0)     // Catch: java.io.IOException -> L7f org.codehaus.jackson.JsonGenerationException -> L85
            if (r0 == 0) goto L62
            r4 = r0
        L62:
            java.lang.String r0 = "contentType"
            r2.writeStringField(r0, r4)     // Catch: java.io.IOException -> L7f org.codehaus.jackson.JsonGenerationException -> L85
            r2.writeEndObject()     // Catch: java.io.IOException -> L7f org.codehaus.jackson.JsonGenerationException -> L85
            r2.close()     // Catch: java.io.IOException -> L7f org.codehaus.jackson.JsonGenerationException -> L85
            java.lang.String r0 = r3.toString()     // Catch: java.io.IOException -> L7f org.codehaus.jackson.JsonGenerationException -> L85
            r3.close()     // Catch: java.io.IOException -> L75 org.codehaus.jackson.JsonGenerationException -> L7a
            goto L8b
        L75:
            r2 = move-exception
            r7 = r2
            r2 = r0
            r0 = r7
            goto L81
        L7a:
            r2 = move-exception
            r7 = r2
            r2 = r0
            r0 = r7
            goto L87
        L7f:
            r0 = move-exception
            r2 = r1
        L81:
            r0.printStackTrace()
            goto L8a
        L85:
            r0 = move-exception
            r2 = r1
        L87:
            r0.printStackTrace()
        L8a:
            r0 = r2
        L8b:
            if (r0 == 0) goto L99
            org.codehaus.jackson.JsonFactory r2 = new org.codehaus.jackson.JsonFactory     // Catch: java.lang.Exception -> L97
            r2.<init>()     // Catch: java.lang.Exception -> L97
            org.codehaus.jackson.JsonParser r0 = r2.createJsonParser(r0)     // Catch: java.lang.Exception -> L97
            goto L9a
        L97:
            goto La3
        L99:
            r0 = r1
        L9a:
            if (r0 == 0) goto La3
            r0.nextToken()     // Catch: java.lang.Exception -> L97
            com.esri.core.map.AttachmentInfo r1 = com.esri.core.map.AttachmentInfo.fromJson(r0)     // Catch: java.lang.Exception -> L97
        La3:
            if (r1 == 0) goto Lb4
            java.lang.String r0 = r8.a(r1)
            if (r0 == 0) goto Lb4
            com.esri.android.map.AttachmentManager r2 = r8.c
            java.io.File r0 = r2.getAttachmentFile(r0)
            r8.a(r9, r0)
        Lb4:
            return r1
        */
        throw new UnsupportedOperationException("Method not decompiled: com.esri.android.map.popup.ArcGISAttachmentsAdapter.a(java.io.File):com.esri.core.map.AttachmentInfo");
    }

    private void a(File file, File file2) {
        FileOutputStream fileOutputStream;
        FileOutputStream fileOutputStream2;
        FileChannel channel;
        FileOutputStream fileOutputStream3;
        if (!file.exists()) {
            return;
        }
        FileInputStream fileInputStream = null;
        try {
            try {
                if (!file2.exists()) {
                    file2.createNewFile();
                }
                FileInputStream fileInputStream2 = new FileInputStream(file);
                try {
                    channel = fileInputStream2.getChannel();
                    fileOutputStream3 = new FileOutputStream(file2);
                } catch (FileNotFoundException e) {
                    e = e;
                    fileOutputStream2 = null;
                    fileInputStream = fileInputStream2;
                } catch (IOException e2) {
                    e = e2;
                    fileOutputStream = null;
                    fileInputStream = fileInputStream2;
                }
                try {
                    FileChannel channel2 = fileOutputStream3.getChannel();
                    if (channel2 == null || channel == null) {
                        return;
                    }
                    channel2.transferFrom(channel, 0L, channel.size());
                } catch (FileNotFoundException e3) {
                    fileInputStream = fileInputStream2;
                    fileOutputStream2 = fileOutputStream3;
                    e = e3;
                    Log.e(com.esri.core.internal.a.a, "Error copying the file", e);
                    if (fileInputStream != null) {
                        try {
                            fileInputStream.close();
                        } catch (IOException unused) {
                        }
                    }
                    if (fileOutputStream2 != null) {
                        fileOutputStream2.close();
                    }
                } catch (IOException e4) {
                    fileInputStream = fileInputStream2;
                    fileOutputStream = fileOutputStream3;
                    e = e4;
                    Log.e(com.esri.core.internal.a.a, "Error copying the file", e);
                    if (fileInputStream != null) {
                        try {
                            fileInputStream.close();
                        } catch (IOException unused2) {
                        }
                    }
                    if (fileOutputStream != null) {
                        fileOutputStream.close();
                    }
                }
            } catch (FileNotFoundException e5) {
                e = e5;
                fileOutputStream2 = null;
            } catch (IOException e6) {
                e = e6;
                fileOutputStream = null;
            }
        } catch (IOException unused3) {
        }
    }
}
